/**
 * @(#)PeriodicSenderRIP.java  Didier Gutacker
 */

/**
 *  @author Didier Gutacker
 *  @version 1.0
 *  @see Periodic
 *  @see NodeRIP
 *  
 */

class PeriodicSenderRIP extends Periodic{
  NodeRIP parent;  
  int toID;

  PeriodicSenderRIP( NodeRIP parent,int to ) {
    this.parent = parent;
    this.toID = to;
    timer = new Thread( parent.getNet().getThreadGroup(), this );
    timer.setPriority( Thread.MIN_PRIORITY );
    timer.start();
  } // PeriodicSenderRIP.PeriodicSenderRIP

  synchronized public void run() {
    parent.paintRequest();
    for ( ;; ) {
      if ( parent.finished() ) {
	return;
      } // if
      parent.sendDataPackets(toID);
      try {
	if ( ! parent.finished() ) {
	  int speed = ((NetworkRIP)parent.getNet()).getSpeed();
	  if ( speed == 1 ) {
	    wait( 4000 );		// every three seconds
	  } else if ( speed == 0 ) {
	    wait( 6000 );
	  } else {
	    wait( 3000 );
	  } // if
	} // if
      } catch( InterruptedException e ) {
      } // try
    } // for
  } // PeriodicSenderRIP.run

  synchronized public int gettoID() {
    return(toID);
  }  

} // PeriodicSenderRIP
